﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Wedo.Recognition.Domain.Models;
using Wedo.Recognition.Domain;
using Wedo.Service.Common;
using Wedo.Recognition.Domain;
using Wedo.Recognition.Repository;

namespace Wedo.Recognition.Service
{
    public class BankService : BaseService<Bank>, IBaseService<Bank>
    {

        #region 基础
        public BankService(IUnitWork dbContext)
            : base(dbContext,dbContext.CacheSet<Bank>())
        {

        }

        /// <summary>
        /// 由银行编号和币种查找银行名称
        /// </summary>
        /// <param name="bankCode"></param>
        /// <param name="currency"></param>
        /// <returns></returns>
        public string GetBankName(string bankCode)
        {
            var bankItem = _repository.Find(s => s.BankCode == bankCode);
            if (bankItem != null)
                return bankItem.BankName;
            return string.Empty;
        }

        /// <summary>
        /// 由银行编号和币种查找银行名称
        /// </summary>
        /// <param name="bankCode"></param>
        /// <param name="currency"></param>
        /// <returns></returns>
        public string GetBankCode(string bankName, string currency)
        {
            var bankItem = _repository.Find(s => s.BankName == bankName && s.Currency == currency);
            if (bankItem != null)
                return bankItem.BankCode;
            return string.Empty;
        }

        /// <summary>
        /// 根据银行名称获取货币列表
        /// </summary>
        /// <param name="bankName">银行名称</param>
        /// <returns>下拉列表</returns>
        public IEnumerable<SelectListItem> GetCurrencyList(string bankName)
        {
            List<SelectListItem> list = new List<SelectListItem>() { new SelectListItem() { Value = "", Text = "", Selected = true } };
            var bList = _repository.Filter(s => s.BankName == bankName).ToList();
            if (bList != null)
            {
                bList.ForEach(s => list.Add(new SelectListItem() { Text = s.Currency, Value = s.Currency }));
            }
            return list;
        }

        /// <summary>
        /// 获取银行名称列表
        /// </summary>
        /// <param name="bankName">银行名称</param>
        /// <returns>下拉列表</returns>
        public IEnumerable<SelectListItem> GetBankList()
        {
            List<SelectListItem> list = new List<SelectListItem>() { new SelectListItem() { Value = "", Text = "", Selected = true } };
            var bList = _repository.All().OrderBy(s => s.BankName).ToList();
            if (bList != null)
            {
                bList.ForEach(s => list.Add(new SelectListItem() { Text = s.BankName + "--" + s.Currency, Value = s.BankCode }));
            }
            return list;
        }

        /// <summary>
        /// 根据银行编号获取货币
        /// </summary>
        /// <param name="bankCode">银行编号</param>
        /// <returns>货币</returns>
        public string GetCurrency(string bankCode)
        {
            if (string.IsNullOrWhiteSpace(bankCode))
                return string.Empty;
            var item = _repository.Find(s => s.BankCode == bankCode);
            if (item != null)
                return item.Currency;
            return string.Empty;
        } 
        #endregion

        #region 业务
        

        #endregion
    }
}
